package com.tengju.activity.domain.shared;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.Getter;

import java.util.Objects;


/**
 * 流水号对象
 */
@Getter
public class TradeNo implements ValueObject<TradeNo> {

    private static final long serialVersionUID = 6940813260197305885L;

    private final String value;

    /**
     * Instantiates a new Id object.
     *
     * @param value the value
     */
    @JsonCreator
    public TradeNo(String value) {
        if (value == null || value.isEmpty()) {
            throw DomainException.error(DomainExceptionCode.ID_SHOULD_BE_POSITIVE);
        }
        this.value = value;
    }

    @JsonValue
    public String getValue() {
        return value;
    }

    @Override
    public boolean sameValueAs(TradeNo other) {
        return other != null && this.value.equals(other.value);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        TradeNo idObject = (TradeNo) o;
        return sameValueAs(idObject);
    }

    @Override
    public int hashCode() {
        return Objects.hash(value);
    }

    @Override
    public String toString() {
        return String.valueOf(value);
    }
}
